import 'package:flutter/material.dart';

import '../model/conversation.dart' show ConversationModel, mu;

class _ConvercationItem extends StatelessWidget {
  const _ConvercationItem({Key key, this.cvMoel})
      : assert(cvMoel != null),
        super(key: key);

  final ConversationModel cvMoel;

  @override
  Widget build(BuildContext context) {
    Widget av = this.cvMoel.isNetAvatar()
        ? Image.network(
            this.cvMoel.avatar,
            width: 64,
            height: 64,
          )
        : Image.asset(this.cvMoel.avatar, width: 64, height: 64);
    var imageHead = Container(
      child: Text(
        '9',
        style: TextStyle(color: Colors.white, fontSize: 12),
      ),
      alignment: Alignment.center,
      height: 16,
      width: 16,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8), color: Colors.red),
    );


    var stackView = Stack(
      overflow: Overflow.visible,
      children: <Widget>[
        av,
        Positioned(
          child: imageHead,
          right: -5,
          top: -2,
        ),
      ],
    );

    return Container(
      decoration: BoxDecoration(
          border: Border(
              bottom:
                  BorderSide(color: Colors.black12, style: BorderStyle.solid))),
      padding: EdgeInsets.all(5),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          stackView,
          Container(
            width: 6,
          ),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  cvMoel.title,
                  style: TextStyle(fontSize: 16, color: Colors.black),
                ),
                Container(
                  height: 15,
                ),
                Text(
                  cvMoel.lastMessage,
                  style: TextStyle(fontSize: 14, color: Colors.black38),
                ),
              ],
            ),
          ),
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[Text('19:00')],
          ),
        ],
      ),
    );
  }
}

class Convercation extends StatefulWidget {
  _ConvercationState createState() => _ConvercationState();
}

class _ConvercationState extends State<Convercation> {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemBuilder: (BuildContext context, int index) {
        print(mu[index].lastMessage);
        return _ConvercationItem(
          cvMoel: mu[index],
        );
      },
      itemCount: mu.length,
    );
  }
}
